package com.ecnu.system.service.impl;

import com.ecnu.common.annotation.DataSource;
import com.ecnu.common.core.domain.AjaxResult;
import com.ecnu.common.enums.DataSourceType;
import com.ecnu.common.utils.StringUtils;
import com.ecnu.common.utils.uuid.IdUtils;
import com.ecnu.system.domain.IncubationFactory;
import com.ecnu.system.domain.IncubationFile;
import com.ecnu.system.domain.vo.IncubationVO;
import com.ecnu.system.mapper.IncubationFactoryMapper;
import com.ecnu.system.mapper.IncubationFileMapper;
import com.ecnu.system.service.IIncubationFactoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>
 * ecnu_二期_成果车间 服务实现类
 * </p>
 *
 * @author zdn
 * @since 2025-11-12
 */
@Service
@DataSource(value = DataSourceType.RESULT)
public class IncubationFactoryServiceImpl
        extends ServiceImpl<IncubationFactoryMapper, IncubationFactory>
        implements IIncubationFactoryService {

    @Autowired
    private IncubationFactoryMapper incubationFactoryMapper;
    @Autowired
    private IncubationFileMapper incubationFileMapper;
    protected String getId() {
        return IdUtils.fastSimpleUUID();
    }
    @Override
    @Transactional
    public AjaxResult editList(List<IncubationVO> maps) {
//        ExecutorService executorService = Executors.newFixedThreadPool(10); // 注入或全局管理
//        executorService.submit(() -> {
            maps.forEach(map -> {
                try {
                    IncubationFactory factory = map.getFactory();
                    if (StringUtils.isNotNull(factory)) {
                        incubationFactoryMapper.insertToData(factory);
                    }
                    IncubationFile file = map.getFiles();
                    if (StringUtils.isNotNull(file)) {
                        incubationFileMapper.insertToData(file);
                    }
                } catch (Exception e) {
                    log.error("保存孵化工厂数据失败", e);
                }
            });
//        });
//        List<IncubationFile> incubationFiles = incubationFileMapper.selectList(null);
        return AjaxResult.success("推送成功");
    }

}
